package com.example.projectcode.controller.Student;

import com.example.projectcode.model.Student;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学生登录注册接口")
@RestController
@RequestMapping(value = "/user/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //    学生登录接口
    @ApiOperation("学生登录接口")
    @GetMapping(value = "/login/{username}/{password}")
    public Result studentLogin(@PathVariable String username,@PathVariable String password){
        Student student = studentService.selectStudent(username,password);
        if (student != null){
            return Result.ok(student);
        }else {
            return Result.fail();
        }

    }


    //学生注册接口
    @ApiOperation(value = "学生注册接口")
    @PostMapping(value = "/register")
    public Result studentRegister(@RequestBody Student student){
        boolean stu = studentService.insertStudent(student);
        if(stu){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }


}
